package com.whh.tq;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

import com.whh.tq.common.AndroidHelper;

/**
 * 查询汇总页面
 * 
 * @author whh023
 * 
 */
public class NavigationActivity extends Activity {

	private LinearLayout btnLeftTicketQuery;
	private LinearLayout btnTimeTableQuery;
	private LinearLayout btnFavorite;
	private LinearLayout btnTicketingAngentQuery;
	private LinearLayout btnSetting;
	private LinearLayout btnTicketCheck;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_navigation);
		//检查网络是否可用，包括gprs和wifi,也可以分开检测
		ConnectivityManager nw = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
		NetworkInfo netInfo = nw.getActiveNetworkInfo();
		if(null == netInfo || !netInfo.isAvailable()){
			AndroidHelper.showToast(getApplicationContext(),"网络不可用");
		}
		init();
	}

	private void init() {
		btnLeftTicketQuery = (LinearLayout) findViewById(R.id.btn_leftTicketQuery);
		btnTimeTableQuery = (LinearLayout) findViewById(R.id.btn_timeTableQuery);
		btnFavorite = (LinearLayout) findViewById(R.id.btn_favorite);
		btnTicketingAngentQuery = (LinearLayout) findViewById(R.id.btn_ticketingAgentQuery);
		btnSetting = (LinearLayout) findViewById(R.id.btn_setting);
		btnTicketCheck = (LinearLayout) findViewById(R.id.btn_ticketCheck);

		btnLeftTicketQuery.setClickable(true);
		btnTimeTableQuery.setClickable(true);
		btnFavorite.setClickable(true);
		btnTicketingAngentQuery.setClickable(true);
		btnSetting.setClickable(true);
		btnTicketCheck.setClickable(true);

		btnLeftTicketQuery.setOnClickListener(leftTicketQueryListener);
		btnTicketCheck.setOnClickListener(ticketCheckListener);
		btnTimeTableQuery.setOnClickListener(timeTableListener);
		btnFavorite.setOnClickListener(favoriteListener);
		btnSetting.setOnClickListener(settingListener);
	}

	private View.OnClickListener leftTicketQueryListener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			Intent intent = new Intent();
			intent.setClass(NavigationActivity.this,LeftTicketInputActivity.class);
			startActivity(intent);
			//窗口切换特效
			//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
		}
	};
	
	private View.OnClickListener ticketCheckListener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			Intent intent = new Intent();
			intent.setClass(NavigationActivity.this,TicketCheckActivity.class);
			startActivity(intent);
			//窗口切换特效
			//overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
		}
	};
	
	private View.OnClickListener timeTableListener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			Intent intent = new Intent();
			intent.setClass(NavigationActivity.this,TimeTableActivity.class);
			startActivity(intent);
		}
	};
	
	private View.OnClickListener favoriteListener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			Intent intent = new Intent();
			intent.setClass(NavigationActivity.this,FavoriteActivity.class);
			startActivity(intent);
		}
	};
	
	private View.OnClickListener settingListener = new OnClickListener() {
		@Override
		public void onClick(View arg0) {
			Intent intent = new Intent();
			intent.setClass(NavigationActivity.this,SettingActivity.class);
			startActivity(intent);
		}
	};
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			new AlertDialog.Builder(this)
					.setIcon(R.drawable.icon)
					.setTitle(R.string.app_name)
					.setMessage(R.string.quit_desc)
					.setNegativeButton(R.string.btn_cancel,
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface dialog,
										int which) {
								}
							})
					.setPositiveButton(R.string.btn_confirm,
							new DialogInterface.OnClickListener() {
								public void onClick(DialogInterface dialog,
										int whichButton) {
									finish();
								}
							}).show();

			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}
}